package day14;

public class homework00001 extends Thread {
    private homework001 baozi;

    public homework00001(homework001 baozi) {
        this.baozi = baozi;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (baozi.getLock()) {
                if (baozi.getCount() == 0) {
                    break;
                } else {
                    if (baozi.getSymbol()) {
                        System.out.println("吃货吃了1个包子");
                        baozi.setNum(baozi.getNum() - 1);
                        if (baozi.getNum() == 0) {
                            System.out.println("吃货吃完5个包子");
                            baozi.setCount(baozi.getCount()-5);
                            baozi.setSymbol(false);
                            baozi.getLock().notify();
                        }
                    }else {
                        try {
                            baozi.getLock().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
